package com.aiwhose.aiwhosewechatplublicaiwhose.utils;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.aiwhose.aiwhosecore.bean.plublicaiwhose.bean.PublicAccountScanEventBean;
import com.aiwhose.aiwhosecore.bean.plublicaiwhose.bean.ReceiveMessageBean;
import com.aiwhose.aiwhosecore.bean.plublicaiwhose.bean.WXPlublicUserInfoBean;
import com.aiwhose.aiwhosewechatplublicaiwhose.service.WXPublicUserService;
import com.aiwhose.aiwhosewechatplublicaiwhose.utils.message.WXMessageCustomerUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

@Component
public class WXEventUtil {
    @Resource
    WXMessageCustomerUtil messageUtil;
    @Resource
    RSAUtil rsaUtil;

    @Resource
    WXPublicUserService wxPublicUserService;


    WXPlublicUserInfoBean subscribeEvent(ReceiveMessageBean.EventMessage eventMessage) throws JsonProcessingException {
        String fromUserName = eventMessage.getFromUserName();
        WXPlublicUserInfoBean userInfo = wxPublicUserService.getUserInfo(fromUserName);
        return userInfo;
    }
    String scanEvent(ReceiveMessageBean.EventMessage eventMessage) throws JsonProcessingException {
        String eventKey = eventMessage.getEventKey();
        byte[] decrypt = rsaUtil.decrypt(eventKey);
        String accountScan = new String(decrypt, StandardCharsets.UTF_8);
        PublicAccountScanEventBean bean = BeanUtil.toBean(JSONUtil.parse(accountScan), PublicAccountScanEventBean.class);
        return "";
    }






}
